package com.conan.spring5.aopAnno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @version 加油！！！
 * @Description
 * @Author 谷藤新一GYC
 * @Date 2022/10/21 - 20:55
 */
//增强类
@Component
@Aspect  //生成代理对象
@Order(3)
public class UserProxy {

    //抽取相同的切入点
    @Pointcut(value = "execution(* com.conan.spring5.aopAnno.User.add(..))")
    public void pointDemo(){

    }

    //前置通知
    //before注解表示前置通知,value可以省略
    @Before(value = "pointDemo()")
    public void before(){
        System.out.println("before.......");
    }
    //表示在方法执行之后执行
    //最终通知
    @After(value = "execution(* com.conan.spring5.aopAnno.User.add(..))")
    public void after(){
        System.out.println("after.........");
    }
    //表示在方法返回结果之后执行
    //后置通知(返回通知)
    @AfterReturning("execution(* com.conan.spring5.aopAnno.User.add(..))")
    public void afterReturning(){
        System.out.println("afterReturning.......");
    }
    //异常通知：有异常才会执行
    @AfterThrowing("pointDemo()")
    public void afterThrowing(){
        System.out.println("afterThrowing........");
    }
    //环绕通知
    @Around("pointDemo()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("around之前............");
        //增强的方法执行
        proceedingJoinPoint.proceed();

        System.out.println("around之后............");
        return null;
    }
}
   